package zhang.automobileservice;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import com.android.volley.Response;
import com.android.volley.VolleyError;

import fragment.MyselfFragment;
import utils.MyUrl;
import utils.RequestQueueUtils;

public class ModifyMessageActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageButton finish;
    private EditText modify_userName,modify_phone;
    private Button bt_modify;
    private String id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify_message);
        initView();
    }

    private void initView() {
        finish = (ImageButton) findViewById(R.id.finish);
        modify_userName = (EditText) findViewById(R.id.modify_userName);
        modify_phone = (EditText) findViewById(R.id.modify_phone);
        bt_modify = (Button) findViewById(R.id.bt_modify);

        finish.setOnClickListener(this);
        bt_modify.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.finish:
                finish();
                break;
            case R.id.bt_modify:
                id = getSharedPreferences("TAGtext",MODE_PRIVATE).getString("id","1");
                String url = MyUrl.Font_Url+MyUrl.updateDetail+"id="+id+"&phone="+modify_phone.getText().toString().trim()+"&userName="+modify_userName.getText().toString().trim();
                RequestQueueUtils.exectueJsonRequest(this, url, new Response.Listener() {
                    @Override
                    public void onResponse(Object o) {
                        Intent intent = new Intent(getApplicationContext(), MyselfFragment.class);
                        startActivity(intent);
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {

                    }
                });
                break;
        }
    }

}
